<template>
  <div class="app-container">
    <el-row :gutter="20">
      <el-col :span="6" :xs="24">
        <el-row>
          <el-col>
            <el-card class="box-card">
              <div slot="header" class="clearfix">
                <span>个人信息</span>
              </div>
              <div>
                <div class="text-center">
                  <userAvatar />
                </div>
                <ul class="list-group list-group-striped">
<!--                  <li class="list-group-item">-->
<!--                    <svg-icon icon-class="user" />用户名称-->
<!--                    <div class="pull-right">{{ user.userName }}</div>-->
<!--                  </li>-->
                  <li class="list-group-item">
                    <svg-icon icon-class="phone" />手机号码
                    <div class="pull-right">{{ user.phonenumber }}</div>
                  </li>
                  <!--              <li class="list-group-item">-->
                  <!--                <svg-icon icon-class="email" />用户邮箱-->
                  <!--                <div class="pull-right">{{ user.email }}</div>-->
                  <!--              </li>-->
                  <!--              <li class="list-group-item">-->
                  <!--                <svg-icon icon-class="tree" />所属部门-->
                  <!--                <div class="pull-right" v-if="user.dept">{{ user.dept.deptName }} / {{ postGroup }}</div>-->
                  <!--              </li>-->
                  <li class="list-group-item">
                    <svg-icon icon-class="peoples" />所属角色
                    <div class="pull-right">{{ roleGroup }}</div>
                  </li>
                  <!--              <li class="list-group-item">-->
                  <!--                <svg-icon icon-class="date" />创建日期-->
                  <!--                <div class="pull-right">{{ user.createTime }}</div>-->
                  <!--              </li>-->
                </ul>
              </div>
            </el-card>
          </el-col>
          <el-col style="margin-top: 20px;">
            <el-card>
              <div slot="header" class="clearfix">
                <span>基本资料</span>
              </div>
              <el-tabs v-model="activeTab">
                <el-tab-pane label="基本资料" name="userinfo">
                  <userInfo :user="user" />
                </el-tab-pane>
                <el-tab-pane label="修改密码" name="resetPwd">
                  <resetPwd />
                </el-tab-pane>
              </el-tabs>
            </el-card>
          </el-col>
        </el-row>
      </el-col>
      <el-col :span="18" :xs="24" >
        <el-card>
          <div slot="header" class="clearfix">
            <span>消息列表</span>
          </div>
          <el-table :data="messages" :height="table_height" >
            <el-table-column prop="title" label="消息标题"></el-table-column>
            <el-table-column prop="readStatus" label="状态" width="100">
              <template slot-scope="scope">
                {{scope.row.readStatus == 0?'未读':'已读'}}
              </template>
            </el-table-column>
            <el-table-column prop="op" label="操作" width="100">
              <template slot-scope="scope">
                <el-button size="mini"
                           type="text" @click="showMessage(scope.row)" >查看</el-button>
              </template>
            </el-table-column>
          </el-table>

          <pagination
            v-show="list_total>0"
            :total="list_total"
            :page.sync="list_params.pageNum"
            :limit.sync="list_params.pageSize"
            @pagination="getMyMessage"
          />
        </el-card>
      </el-col>

<!--      <el-col :span="6" style="margin-top: 20px;" :xs="24">-->

<!--      </el-col>-->
    </el-row>
    <el-dialog :visible.sync="dialog_show" title="站内信">
      <el-form >
        <el-form-item label="消息标题">
          <el-input v-model="message.title" readonly></el-input>
        </el-form-item>
        <el-form-item label="消息内容">
          <!--          <el-input v-model="message.content" type="textarea" readonly ></el-input>-->
        </el-form-item>
        <div v-html="message.content" style="max-height: 400px;overflow: auto;" class="information-main-content"></div>
      </el-form>
    </el-dialog>

  </div>
</template>

<script>
import userAvatar from "./userAvatar";
import userInfo from "./userInfo";
import resetPwd from "./resetPwd";
import { getUserProfile } from "@/api/system/user";
import { my, read } from '@/api/base/message'

export default {
  name: "Profile",
  components: { userAvatar, userInfo, resetPwd },
  data() {
    return {
      table_height:window.innerHeight - 300,
      dialog_show:false,
      user: {},
      roleGroup: {},
      postGroup: {},
      activeTab: "userinfo",
      messages:[],
      message:{},
      list_params:{
        pageNum: 1,
        pageSize: 10
      },
      list_total:0
    };
  },
  created() {
    this.getUser();
    this.getMyMessage()
  },
  methods: {
    getMyMessage(){
      my().then((res)=>{
        this.messages = res.rows;
        this.list_total = res.total;
      })
    },
    getUser() {
      getUserProfile().then(response => {
        this.user = response.data;
        this.roleGroup = response.roleGroup;
        this.postGroup = response.postGroup;
      });
    },
    showMessage(row){
      console.log(row)
      read(row.id).then((res)=>{
        this.getMyMessage()
      })
      this.message = row;
      this.dialog_show = true
    }
  }
};
</script>

<style scoped>
.information-main-content img{
  max-width: 100%;
  height: auto;
}
</style>
<style >
.information-main-content img{
  max-width: 100%;
  height: auto;
}
</style>
